package com.hongning.railway.ui.main.mine.partcheck;

import android.app.Application;
import android.databinding.ObservableArrayList;
import android.databinding.ObservableList;
import android.support.annotation.NonNull;

import com.hongning.railway.R;
import com.hongning.railway.data.AppRepository;
import com.hongning.railway.entity.reqbean.ReqKaoHeGroupBean;
import com.hongning.railway.entity.resbean.ResKaoHeBean;
import com.hongning.railway.ui.main.mine.partcheck.itemviewmodel.PartCheckSecondItemViewModel;
import com.hongning.railway.util.Apputils;
import com.hongning.railway.util.GsonUtil;

import java.util.List;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.http.ApiDisposableObserver;
import me.goldze.mvvmhabit.utils.RxUtils;
import me.tatarka.bindingcollectionadapter2.BR;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class PartCheckSecondFragmentViewModel extends BaseViewModel<AppRepository> {
    public ItemBinding<PartCheckSecondItemViewModel> itemBinding = ItemBinding.of(BR.viewModel, R.layout.item_party_check_second);
    public ObservableList<PartCheckSecondItemViewModel> viewlist = new ObservableArrayList<>();

    public PartCheckSecondFragmentViewModel(@NonNull Application application) {
        super(application);
    }


    public PartCheckSecondFragmentViewModel(@NonNull Application application, AppRepository model) {
        super(application, model);
    }


    public void loadData(String id){
        ReqKaoHeGroupBean reqKaoHeGroupBean = new ReqKaoHeGroupBean();
        reqKaoHeGroupBean.setId(id);
        reqKaoHeGroupBean.setGroupId(Apputils.getGroupId());
        reqKaoHeGroupBean.setStaffId(Apputils.getStaffid());
        model.getPartyExamInfoDetailsById(reqKaoHeGroupBean)
                .compose(RxUtils.schedulersTransformer())
                .compose(RxUtils.bindToLifecycle(getLifecycleProvider()))
                .subscribe(new ApiDisposableObserver<List<ResKaoHeBean>>() {
                    @Override
                    public void onResult(List<ResKaoHeBean> resKaoHeBeans) {
                        for (ResKaoHeBean data:resKaoHeBeans) {
                            viewlist.add(new PartCheckSecondItemViewModel(PartCheckSecondFragmentViewModel.this,data));
                        }
                    }
                });
    }
}
